package com.bajiao.admin.controller.recharge;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bajiao.admin.base.AdminBaseController;
import com.bajiao.common.api.vo.Result;
import com.bajiao.entity.recharge.RechargeMenu;
import com.bajiao.service.recharge.RechargeMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 充值菜单
 * @Author: FanJq
 * @Date:   2024-03-17
 * @Version: V1.0
 */
@Slf4j
@Api(tags="充值菜单")
@RestController
@RequestMapping("/recharge/menu")
public class RechargeMenuController extends AdminBaseController<RechargeMenu, RechargeMenuService> {

	@Resource
	private RechargeMenuService rechargeMenuService;

	/**
	 * @description: 分页列表查询
	 @author: FanJq
	 * @date:   2024-03-17
	 * @return
	 */
	@ApiOperation(value="充值菜单-分页列表查询", notes="充值菜单-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList() {
		LambdaQueryWrapper<RechargeMenu> queryWrapper = new LambdaQueryWrapper<>();
		queryWrapper.eq(RechargeMenu::getDelFlag,0).orderByAsc(RechargeMenu::getPrice);
		startPage();
		queryWrapper.orderByAsc(RechargeMenu::getPrice);
		List<RechargeMenu> list = rechargeMenuService.list(queryWrapper);
		return Result.ok(getDataTable(list));
	}

	/**
	 * @description: 添加
	 @author: FanJq
	 * @date:   2024-03-17
	 * @param rechargeMenu
	 * @return
	 */
	@ApiOperation(value="充值菜单-添加", notes="充值菜单-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody RechargeMenu rechargeMenu) {
		rechargeMenuService.save(rechargeMenu);
		return Result.ok("添加成功！");
	}

	/**
	 * @description: 编辑
	 @author: FanJq
	 * @date:   2024-03-17
	 * @param rechargeMenu
	 * @return
	 */
	@ApiOperation(value="充值菜单-编辑", notes="充值菜单-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody RechargeMenu rechargeMenu) {
		rechargeMenuService.updateById(rechargeMenu);
		return Result.ok("编辑成功!");
	}

	/**
	 * @description: 通过id删除
	 @author: FanJq
	 * @date:   2024-03-17
	 * @param id
	 * @return
	 */
	@ApiOperation(value="充值菜单-通过id删除", notes="充值菜单-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		rechargeMenuService.removeById(id);
		return Result.ok("删除成功!");
	}

	/**
	 * @description: 批量删除
	 @author: FanJq
	 * @date:   2024-03-17
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="充值菜单-批量删除", notes="充值菜单-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.rechargeMenuService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功！");
	}

	/**
	 * @description: 通过id查询
	 @author: FanJq
	 * @date:   2024-03-17
	 * @param id
	 * @return
	 */
	@ApiOperation(value="充值菜单-通过id查询", notes="充值菜单-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		RechargeMenu rechargeMenu = rechargeMenuService.getById(id);
		return Result.ok(rechargeMenu);
	}

  /**
   * @description: 导出excel
   @author: FanJq
   * @date:   2024-03-17
   * @param request
   * @param rechargeMenu
   */
  @RequestMapping(value = "/exportXls")
  public ModelAndView exportXls(HttpServletRequest request, RechargeMenu rechargeMenu) {
      return super.exportXls(request, rechargeMenu, RechargeMenu.class, "充值菜单");
  }

  /**
   * @description: 通过excel导入数据
   @author: FanJq
   * @date:   2024-03-17
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      return super.importExcel(request, response, RechargeMenu.class);
  }

}
